package com.neusoft.elmboot.controller;

import com.neusoft.elmboot.po.Orders;
import com.neusoft.elmboot.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/Orders")
public class OrdersController {
	@Autowired

	private OrdersService ordersService;

	@GetMapping("/OrdersList")
	public List<Orders> listOrdersByUserId(Orders orders) throws Exception {
		return ordersService.listOrdersByUserId(orders.getUserId());
	}

	@PostMapping("/OrdersId")
	public int createOrders(Orders orders) throws Exception {
		return ordersService.createOrders(orders);
	}

	@GetMapping("/OrdersId")
	public Orders getOrderById(Orders orders) throws Exception {
		return ordersService.getOrdersById(orders.getOrderId());
	}

	// 特殊
	@PutMapping("/OrdersId")
	public int updateOrder(Orders orders) throws Exception {
		return ordersService.updateOrder(orders);
	}

	@DeleteMapping("/OrdersId")
	public int removeOrders(Orders orders) throws Exception {
		return ordersService.removeOrders(orders.getOrderId());
	}
}